package com.gitee.wsl.net.client.apiclient.request

import io.ktor.client.statement.HttpResponse
import io.ktor.http.isSuccess

interface RemoteResponse {
    val request: RemoteRequest
    val body: String
    val status: Int
    val statusText: String
    val ok: Boolean

    val is4xx: Boolean get() = status in 400..499
    val is5xx: Boolean get() = status in 500..599
}


class RemoteResponseImpl(
    override val request: RemoteRequest,
    private val response: HttpResponse,
    private val responseBody: String,
) : RemoteResponse {
    override val body: String get() = responseBody

    override val status: Int get() = response.status.value

    override val statusText: String get() = response.status.description

    override val ok: Boolean get() = response.status.isSuccess()

    override val is4xx: Boolean get() = status in 400..499

    override val is5xx: Boolean get() = status in 500..599
}